/**
 * @description router全局配置，如有必要可分文件抽离，其中asyncRoutes只有在intelligence模式下才会用到，pro版只支持remixIcon图标，具体配置请查看vip群文档
 */
import type { RouteRecordName, RouteRecordRaw } from 'vue-router'
import type { VabRouteRecord } from '/#/router'
import {
  createRouter,
  createWebHashHistory,
  createWebHistory,
} from 'vue-router'
import Layout from '@vab/layouts/index.vue'
import { setupPermissions } from './permissions'
import { authentication, isHashRouterMode, publicPath } from '@/config'

export const constantRoutes: VabRouteRecord[] = [
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/login/index.vue'),
    meta: {
      hidden: true,
    },
  },
  {
    path: '/dingtalk',
    name: 'DingTalk',
    component: () => import('@/views/login/dingtalk.vue'),
    meta: {
      hidden: true,
    },
  },
  {
    path: '/register',
    name: 'Register',
    component: () => import('@/views/register/index.vue'),
    meta: {
      hidden: true,
    },
  },
  {
    path: '/callback',
    name: 'Callback',
    component: () => import('@/views/callback/index.vue'),
    meta: {
      hidden: true,
    },
  },
  {
    path: '/403',
    name: '403',
    component: () => import('@/views/403.vue'),
    meta: {
      hidden: true,
    },
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/404.vue'),
    meta: {
      hidden: true,
    },
  },
  // {
  //   path: '/trackingList',
  //   name: 'TrackingList',
  //   component: () => import('@/views/customer/tracking/tracklist/index.vue'),
  //   meta: {
  //     title: '跟进记录',
  //   },
  // },
]

export const asyncRoutes: VabRouteRecord[] = [
  {
    path: '/',
    name: 'Root',
    component: Layout,
    meta: {
      title: '首页',
      icon: 'home-2-line',
      breadcrumbHidden: true,
    },
    children: [
      {
        path: 'index',
        name: 'Index',
        component: () => import('@/views/index/index.vue'),
        meta: {
          title: '首页工作台',
          icon: 'home-2-line',
          noClosable: true,
        },
      },
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('@/views/index/dashboard.vue'),
        meta: {
          title: '数据统计看板',
          icon: 'bar-chart-box-line',
        },
      },
      {
        path: 'teamwork',
        name: 'TeamWork',
        // component: () => import('@/views/teamwork/index.vue'),
        meta: {
          title: '协同工作台',
          icon: 'file-word-2-line',
        },
        children: [
          // {
          //   path: 'teamworkIndex',
          //   name: 'teamworkIndex',
          //   component: () => import('@/views/teamwork/index.vue'),
          //   meta: {
          //     title: '协同纵览',
          //     icon: 'slideshow-line',
          //   },
          // },
          {
            path: 'update',
            name: 'Update',
            component: () => import('@/views/teamwork/update/index.vue'),
            meta: {
              title: '更新通知',
              icon: 'base-station-line',
            },
          },
          {
            path: 'feedback',
            name: 'Feedback',
            component: () => import('@/views/teamwork/feedback/index.vue'),
            meta: {
              title: '意见反馈',
              icon: 'draft-line',
              dot: true,
            },
          },
          {
            path: 'attachment',
            name: 'Attachment',
            component: () => import('@/views/teamwork/attachment/index.vue'),
            meta: {
              title: '附件集合',
              icon: 'attachment-2',
            },
          },
          {
            path: 'apidoc',
            name: 'ApiDoc',
            component: () => import('@/views/teamwork/apidoc/index.vue'),
            meta: {
              title: '接口文档',
              icon: 'calendar-2-line',
            },
          },
          // {
          //   path: 'schedule',
          //   name: 'Schedule',
          //   component: () => import('@/views/teamwork/schedule/index.vue'),
          //   meta: {
          //     title: '进度预览',
          //     icon: 'calendar-2-line',
          //   },
          // },
        ],
      },
      {
        path: 'remixIcon',
        name: 'RemixIcon',
        component: () => import('@/views/vab/icon/remixIcon.vue'),
        meta: {
          title: '图标采纳',
          icon: 'image-2-line',
        },
      },
      // {
      //   path: 'store',
      //   name: 'Store',
      //   component: () => import('@/views/index/store.vue'),
      //   meta: {
      //     title: '仓库',
      //     icon: 'app-store-line',
      //     dot: true,
      //   },
      // },
    ],
  },
  {
    path: '/systemset',
    name: 'SystemSet',
    component: Layout,
    meta: {
      title: '设置',
      icon: 'settings-3-line',
    },
    children: [
      // {
      //   path: 'cityarea',
      //   name: 'CityArea',
      //   component: () => import('@/views/systemset/cityarea/index.vue'),
      //   meta: {
      //     title: '区域设置',
      //     icon: 'chat-settings-fill',
      //   },
      // },
      // {
      //   path: 'city',
      //   name: 'City',
      //   component: () => import('@/views/systemset/cityarea/city.vue'),
      //   meta: {
      //     title: '城市设置',
      //     icon: 'chat-settings-fill',
      //     hidden: true,
      //   },
      // },
      {
        path: 'industry',
        name: 'Industry',
        component: () => import('@/views/systemset/industry/index.vue'),
        meta: {
          title: '行业设置',
          icon: 'remixicon-line',
        },
      },
      {
        path: 'organization',
        name: 'Organization',
        meta: {
          title: '组织架构设置',
          icon: 'organization-chart',
        },
        children: [
          // {
          //   path: 'company',
          //   name: 'Company',
          //   component: () =>
          //     import('@/views/systemset/organization/company/index.vue'),
          //   meta: {
          //     title: '组织设置',
          //   },
          // },
          {
            path: 'company',
            name: 'Company',
            component: () =>
              import('@/views/systemset/organization/company/index.vue'),
            meta: {
              // tabHidden: true,
              title: '组织设置',
              // dynamicNewTab: true,
            },
          },
          {
            path: 'department',
            name: 'Department',
            component: () =>
              import('@/views/systemset/organization/department/index.vue'),
            meta: {
              title: '部门设置',
              hidden: true,
              tabHidden: true,
            },
          },
          {
            path: 'staffpost',
            name: 'StaffPost',
            component: () =>
              import('@/views/systemset/organization/staffpost/index.vue'),
            meta: {
              title: '职位设置',
              hidden: true,
              tabHidden: true,
            },
          },
          {
            path: 'staffpost',
            name: 'staffpost',
            component: () =>
              import('@/views/systemset/organization/staffpost/index.vue'),
            meta: {
              title: '职位岗级设置',
            },
          },
          {
            path: 'staff',
            name: 'Staff',
            component: () =>
              import('@/views/systemset/organization/staff/index.vue'),
            meta: {
              title: '员工管理',
            },
          },
        ],
      },
      {
        path: 'businessset',
        name: 'BusinessSet',
        meta: {
          title: '业务产品设置',
          icon: 'remixicon-line',
        },
        children: [
          {
            path: 'businessClass',
            name: 'BusinessClass',
            component: () =>
              import('@/views/systemset/business/class/index.vue'),
            meta: {
              title: '业务类型设置',
            },
          },
          {
            path: 'product',
            name: 'Product',
            component: () =>
              import('@/views/systemset/business/product/index.vue'),
            meta: {
              title: '产品设置',
            },
          },
          {
            path: 'gift',
            name: 'Gift',
            component: () =>
              import('@/views/systemset/business/gift/index.vue'),
            meta: {
              title: '赠品设置',
            },
          },
        ],
      },
      // {
      //   path: 'dict',
      //   name: 'Dict',
      //   meta: {
      //     title: '参数字典设置',
      //     icon: 'remixicon-line',
      //   },
      //   children: [
      //     {
      //       path: 'payType',
      //       name: 'PayType',
      //       component: () =>
      //         import('@/views/systemset/business/class/index.vue'),
      //       meta: {
      //         title: '收款方式设置',
      //       },
      //     },
      //   ],
      // },
      // {
      //   path: 'dict',
      //   name: 'Dict',
      //   meta: {
      //     title: '业务规则设置',
      //     icon: 'remixicon-line',
      //   },
      //   children: [
      //     {
      //       path: 'class',
      //       name: 'Class',
      //       component: () =>
      //         import('@/views/systemset/business/class/index.vue'),
      //       meta: {
      //         title: '积分规则',
      //       },
      //     },
      //   ],
      // },
      {
        path: 'other',
        name: 'Other',
        meta: {
          title: '其它设置',
          icon: 'remixicon-line',
        },
        children: [
          {
            path: 'earlywarning',
            name: 'EarlyWarning',
            component: () =>
              import('@/views/systemset/other/earlywarning/index.vue'),
            meta: {
              title: '相关预警设置',
            },
          },
          // {
          //   path: 'class',
          //   name: 'Class',
          //   component: () =>
          //     import('@/views/systemset/other/integral/index.vue'),
          //   meta: {
          //     title: '积分规则',
          //   },
          // },
        ],
      },
    ],
  },
  {
    path: '/customer',
    name: 'Customer',
    component: Layout,
    meta: {
      title: '客户',
      icon: 'account-pin-box-line',
    },
    children: [
      {
        path: 'searchPick',
        name: 'SearchPick',
        component: () => import('@/views/customer/searchpick/index.vue'),
        meta: {
          title: '检索挑入/新增录入',
          icon: 'remixicon-line',
        },
      },
      {
        path: 'createCustomer',
        name: 'CreateCustomer',
        component: () => import('@/views/customer/create.vue'),
        meta: {
          title: '批量导入客户资源',
          icon: 'remixicon-line',
        },
      },
      {
        path: 'openSeaClass',
        name: 'OpenSeaClass',
        meta: {
          title: '公海资源',
          icon: 'remixicon-line',
        },
        children: [
          {
            path: 'opensea',
            name: 'Opensea',
            component: () => import('@/views/customer/opensea/index.vue'),
            meta: {
              title: '公海客户资源',
            },
          },
          {
            path: 'terminated',
            name: 'Terminated',
            component: () => import('@/views/customer/terminateds/index.vue'),
            meta: {
              title: '已终止合作的客户资源',
            },
          },
        ],
      },
      {
        path: 'newSignClass',
        name: 'NewSignClass',
        meta: {
          title: '已挑入的新签资源',
          icon: 'remixicon-line',
        },
        children: [
          {
            path: 'opennewsignature',
            name: 'OpenNewSignature',
            component: () =>
              import('@/views/customer/opennewsignature/index.vue'),
            meta: {
              title: '公海新签资源',
            },
          },
          {
            path: 'inseanewsignature',
            name: 'Inseanewsignature',
            component: () =>
              import('@/views/customer/inseanewsignature/index.vue'),
            meta: {
              title: '内海新签资源',
            },
          },
        ],
      },
      {
        path: 'sustainedSigning',
        name: 'SustainedSigning',
        meta: {
          title: '续签客户资源',
          icon: 'remixicon-line',
        },
        children: [
          {
            path: 'serviceing',
            name: 'Serviceing',
            component: () => import('@/views/customer/serviceing/index.vue'),
            meta: {
              title: '我的续签资源',
            },
          },
        ],
      },
      {
        path: 'Signed',
        name: 'Signed',
        component: () => import('@/views/customer/signed/index.vue'),
        meta: {
          title: '合作中客户',
          icon: 'remixicon-line',
        },
      },
      {
        path: 'terminateds',
        name: 'Terminateds',
        component: () => import('@/views/customer/terminated/index.vue'),
        meta: {
          title: '已终止合作的客户',
          icon: 'remixicon-line',
        },
      },
      {
        path: 'track',
        name: 'Track',
        component: () => import('@/views/customer/tracking/index.vue'),
        meta: {
          title: '我的跟进计划',
          icon: 'remixicon-line',
        },
        children: [
          // {
          //   path: 'tracking',
          //   name: 'Tracking',
          //   component: () => import('@/views/customer/tracking/index.vue'),
          //   meta: {
          //     title: '所有跟进中客户',
          //   },
          // },
          // {
          //   path: 'subTracking',
          //   name: 'SubTracking',
          //   component: () => import('@/views/customer/tracking/index.vue'),
          //   meta: {
          //     title: '下属跟进中客户',
          //   },
          // },
          // {
          //   path: 'myTracking',
          //   name: 'MyTracking',
          //   component: () => import('@/views/customer/tracking/index.vue'),
          //   meta: {
          //     title: '我的跟进中客户',
          //   },
          // },
          {
            path: 'myTrackplan',
            name: 'MyTrackingplan',
            component: () => import('@/views/customer/trackingplan/index.vue'),
            meta: {
              title: '我的联系跟进计划',
            },
          },
          {
            path: 'nocontactwarn',
            name: 'NoContactWarn',
            component: () => import('@/views/customer/nocontactwarn/index.vue'),
            meta: {
              title: '5天以上未跟进提醒',
            },
          },
          {
            path: 'losswarn',
            name: 'LossWarn',
            component: () => import('@/views/customer/losswarn/index.vue'),
            meta: {
              title: '即将流出预警提醒',
            },
          },
          {
            path: 'trackingBusiness',
            name: 'TrackingBusiness',
            component: () =>
              import('@/views/customer/tracking/business/index.vue'),
            meta: {
              title: '跟进中业务商机',
              hidden: true,
            },
          },
          {
            path: 'trackingList',
            name: 'TrackingList',
            component: () =>
              import('@/views/customer/tracking/tracklist/index.vue'),
            meta: {
              title: '跟进记录',
              hidden: true,
            },
          },
        ],
      },
      {
        path: 'dataedit',
        name: 'DataEdit',
        component: () => import('@/views/customer/dataedit/index.vue'),
        meta: {
          title: '客户资料维护',
          icon: 'remixicon-line',
        },
      },
      {
        path: 'pickcheck',
        name: 'Dickcheck',
        component: () => import('@/views/customer/pickcheck/index.vue'),
        meta: {
          title: '申请挑入审核',
          icon: 'remixicon-line',
        },
      },
      {
        path: 'all',
        name: 'All',
        component: () => import('@/views/business/all/index.vue'),
        meta: {
          title: '所有商机管理',
          icon: 'remixicon-line',
        },
      },
      {
        path: 'info',
        name: 'Info',
        component: () => import('@/views/customer/info/index.vue'),
        meta: {
          title: '客户详情',
          icon: 'remixicon-line',
          hidden: true,
        },
      },
      {
        path: 'database',
        name: 'Database',
        component: () => import('@/views/customer/database/index.vue'),
        meta: {
          title: '客户跟进统计',
          icon: 'remixicon-line',
        },
      },
    ],
  },
  {
    path: '/business',
    name: 'Business',
    component: Layout,
    meta: {
      title: '业务',
      icon: 'apps-line',
    },
    children: [
      {
        path: 'order',
        name: 'Order',
        meta: {
          title: '业务单',
          icon: 'exchange-cny-line',
        },
        children: [
          {
            path: 'allOrder',
            name: 'AllOrder',
            component: () => import('@/views/business/order/index.vue'),
            meta: {
              title: '业务单管理',
            },
          },
          {
            path: 'createIndex',
            name: 'CreateIndex',
            component: () => import('@/views/business/order/create/index.vue'),
            meta: {
              title: '到单录入',
            },
          },
          {
            path: 'createOrder',
            name: 'CreateOrder',
            component: () => import('@/views/business/order/create/order.vue'),
            meta: {
              title: '到单录入',
              hidden: true,
            },
          },
          {
            path: 'create',
            name: 'Create',
            component: () => import('@/views/business/order/create/index.vue'),
            meta: {
              title: '分期到款录入',
            },
          },
          {
            path: 'submitOrder',
            name: 'SubmitOrder',
            component: () => import('@/views/business/submit/order.vue'),
            meta: {
              title: '审核提单',
              hidden: true,
            },
          },
          {
            path: 'payment',
            name: 'Payment',
            component: () => import('@/views/business/payment/index.vue'),
            meta: {
              title: '出纳收款确认',
            },
          },
          {
            path: 'invoicing',
            name: 'Invoicing',
            component: () => import('@/views/business/invoicing/index.vue'),
            meta: {
              title: '财务开发票',
            },
          },
          {
            path: 'submitOrderList',
            name: 'SubmitOrderList',
            component: () => import('@/views/business/submit/index.vue'),
            meta: {
              title: '业务提单',
            },
          },
          {
            path: 'reviewsplitorders',
            name: 'ReviewSplitOrders',
            component: () =>
              import('@/views/business/reviewsplitorders/index.vue'),
            meta: {
              title: '审核提单/并分单',
            },
          },
          {
            path: 'reviewOrder',
            name: 'ReviewOrder',
            component: () =>
              import('@/views/business/reviewsplitorders/revieworder.vue'),
            meta: {
              title: '审核提单',
              hidden: true,
            },
          },
        ],
      },
      {
        path: 'shopOperate',
        name: 'ShopOperate',
        meta: {
          title: '运营任务',
          icon: 'database-line',
        },
        children: [
          {
            path: 'allStore',
            name: 'AllStore',
            component: () => import('@/views/store/index.vue'),

            meta: {
              title: '店长所辖运营任务管理',
            },
          },
          {
            path: 'storeOperate',
            name: 'StoreOperate',
            component: () => import('@/views/store/operate/index.vue'),
            meta: {
              title: '运营师运营任务管理',
            },
          },
          {
            path: 'jifen',
            name: 'Jifen',
            component: () => import('@/views/customer/jifen/index.vue'),
            meta: {
              title: '客户积分管理',
            },
          },
          {
            path: 'storeDetails',
            name: 'StoreDetails',
            component: () => import('@/views/store/details/index.vue'),
            meta: {
              title: '运营任务详情',
              hidden: true,
            },
          },
        ],
      },
      {
        path: 'worktask',
        name: 'WorkTask',
        meta: {
          title: '工作任务',
          icon: 'todo-line',
        },
        children: [
          {
            path: 'worktaskAll',
            name: 'WorkTaskAll',
            component: () => import('@/views/worktask/index.vue'),
            meta: {
              title: '工作任务管理',
            },
          },
          {
            path: 'worktaskWorkallinfo',
            name: 'WorktaskWorkallinfo',
            component: () => import('@/views/worktask/workallinfo/index.vue'),
            meta: {
              title: '工作任务详情',
              hidden: true,
            },
          },
          {
            path: 'designertask',
            name: 'DesignerTask',
            component: () => import('@/views/worktask/designer/index.vue'),
            meta: {
              title: '美工任务',
            },
          },
          {
            path: 'designertaskinfo',
            name: 'DesignerTaskInfo',
            component: () => import('@/views/worktask/designer/taskinfo.vue'),
            meta: {
              title: '美工任务详情',
              hidden: true,
            },
          },
          {
            path: 'videoertask',
            name: 'VideoerTask',
            component: () => import('@/views/worktask/videoer/index.vue'),
            meta: {
              title: '影像任务',
            },
          },
          {
            path: 'videoertaskinfo',
            name: 'VideoerTaskInfo',
            component: () => import('@/views/worktask/videoer/taskinfo.vue'),
            meta: {
              title: '影像工单任务详情',
              hidden: true,
            },
          },
          {
            path: 'websitetask',
            name: 'WebsiteTask',
            component: () => import('@/views/worktask/website/index.vue'),
            meta: {
              title: '网页任务',
            },
          },
          {
            path: 'websitetaskinfo',
            name: 'WebsiteTaskInfo',
            component: () => import('@/views/worktask/website/taskinfo.vue'),
            meta: {
              title: '网站任务详情',
              hidden: true,
            },
          },
          {
            path: 'developertask',
            name: 'DeveloperTask',
            component: () => import('@/views/worktask/developer/index.vue'),
            meta: {
              title: '开发任务',
            },
          },
          {
            path: 'developertaskinfo',
            name: 'DeveloperTaskInfo',
            component: () => import('@/views/worktask/developer/taskinfo.vue'),
            meta: {
              title: '开发任务详情',
              hidden: true,
            },
          },
        ],
      },
      {
        path: 'satisfaction',
        name: 'Satisfaction',
        meta: {
          title: '客满管理',
          icon: 'database-line',
        },
        children: [
          {
            path: 'satisfactionQuery',
            name: 'SatisfactionQuery',
            component: () => import('@/views/business/satisfaction/index.vue'),
            meta: {
              title: '客满查询',
            },
          },
          {
            path: 'satisfactionTrack',
            name: 'SatisfactionTrack',
            component: () => import('@/views/business/satisfaction/index.vue'),
            meta: {
              title: '客满跟进小记',
            },
          },
          {
            path: 'satisfactionDetails',
            name: 'SatisfactionDetails',
            component: () =>
              import('@/views/business/satisfaction/details/index.vue'),
            meta: {
              title: '客满详情',
              hidden: true,
            },
          },
        ],
      },
      {
        path: 'businessService',
        name: 'BusinessService',
        meta: {
          title: '业务产品总览',
          icon: 'database-line',
        },
        children: [
          {
            path: 'allService',
            name: 'AllService',
            component: () => import('@/views/business/service/index.vue'),
            meta: {
              title: '所有签约业务产品',
            },
          },
          {
            path: 'businessServiceing',
            name: 'businessServiceing',
            component: () =>
              import('@/views/business/service/serviceing/index.vue'),
            meta: {
              title: '所有服务中业务产品',
            },
          },
          {
            path: 'businessExpired',
            name: 'BusinessExpired',
            component: () =>
              import('@/views/business/service/serviceing/index.vue'),
            meta: {
              title: '已过期业务产品',
              hidden: true,
            },
          },
        ],
      },
    ],
  },
  {
    path: '/report',
    name: 'Report',
    component: Layout,
    meta: {
      title: '报表',
      icon: 'bar-chart-box-line',
    },
    children: [
      {
        path: 'designer',
        name: 'Designer',
        component: () => import('@/views/report/designer/index.vue'),
        meta: {
          title: '美工提成总表',
          icon: 'chat-poll-line',
        },
      },
      {
        path: 'videogroup',
        name: 'VideoGroup',
        component: () => import('@/views/report/videogroup/index.vue'),
        meta: {
          title: '视频组提成总表',
          icon: 'chat-poll-line',
        },
      },
      {
        path: 'hostedservices',
        name: 'HostedServices',
        component: () => import('@/views/report/hostedservices/index.vue'),
        meta: {
          title: '托管服务包业绩表',
          icon: 'chat-poll-line',
        },
      },
      {
        path: 'operationstoremanager',
        name: 'OperationStoreManager',
        component: () =>
          import('@/views/report/operationstoremanager/index.vue'),
        meta: {
          title: '运营部店长业绩',
          icon: 'chat-poll-line',
        },
      },
      {
        path: 'operationmanager',
        name: 'OperationManager',
        component: () => import('@/views/report/operationmanager/index.vue'),
        meta: {
          title: '运营部主管业绩',
          icon: 'chat-poll-line',
        },
      },
      {
        path: 'operationrenew',
        name: 'OperationRenew',
        component: () => import('@/views/report/operationrenew/index.vue'),
        meta: {
          title: '运营部新签续费明细',
          icon: 'chat-poll-line',
        },
      },
      {
        path: 'notyetmade',
        name: 'NotYetMade',
        component: () => import('@/views/report/notyetmade/index.vue'),
        meta: {
          title: '运营部未开始制作表',
          icon: 'chat-poll-line',
        },
      },
      {
        path: 'pausestore',
        name: 'PauseStore',
        component: () => import('@/views/report/pausestore/index.vue'),
        meta: {
          title: '暂停店铺数据表',
          icon: 'chat-poll-line',
        },
      },
      {
        path: 'tiktokstore',
        name: 'TiktokStore',
        component: () => import('@/views/report/tiktokstore/index.vue'),
        meta: {
          title: '抖店运营业绩明细表',
          icon: 'chat-poll-line',
        },
      },
      {
        path: 'achievementlist',
        name: 'AchievementList',
        component: () => import('@/views/report/achievementlist/index.vue'),
        meta: {
          title: '业绩明细表',
          icon: 'chat-poll-line',
        },
      },
      {
        path: 'yearlyrenew',
        name: 'YearlyRenew',
        component: () => import('@/views/report/yearlyrenew/index.vue'),
        meta: {
          title: '年度续费明细数据总表',
          icon: 'chat-poll-line',
        },
      },
    ],
  },
  {
    path: '/my',
    name: 'My',
    component: Layout,
    meta: {
      title: '我的',
      icon: 'user-settings-line',
    },
    children: [
      {
        path: 'personalCenter',
        name: 'PersonalCenter',
        component: () => import('@/views/my/personalCenter/index.vue'),
        meta: {
          title: '我的账户信息',
          icon: 'map-pin-user-line',
        },
      },
      {
        path: 'authority',
        name: 'Authority',
        component: () => import('@/views/my/authority/index.vue'),
        meta: {
          title: '我的权限',
          icon: 'user-3-line',
        },
      },
      {
        path: 'noticeCenter',
        name: 'NoticeCenter',
        component: () => import('@/views/my/noticecenter/index.vue'),
        meta: {
          title: '消息中心',
          icon: 'map-pin-user-line',
        },
      },
    ],
  },
  {
    path: '/setting',
    name: 'PersonnelManagement',
    component: Layout,
    meta: {
      title: '系统',
      icon: 'user-settings-line',
      guard: ['Admin'],
    },
    children: [
      {
        path: 'menuManagement',
        name: 'MenuManagement',
        component: () => import('@/views/setting/menuManagement/index.vue'),
        meta: {
          title: '菜单管理',
          icon: 'menu-2-fill',
        },
      },
      {
        path: 'systemLog',
        name: 'SystemLog',
        component: () => import('@/views/setting/systemLog/index.vue'),
        meta: {
          title: '系统日志',
          icon: 'file-shield-2-line',
        },
      },
    ],
  },
  {
    path: '/:pathMatch(.*)*',
    redirect: '/404',
    name: 'NotFound',
    meta: {
      hidden: true,
    },
  },
]

const router = createRouter({
  history: isHashRouterMode
    ? createWebHashHistory(publicPath)
    : createWebHistory(publicPath),
  routes: constantRoutes as RouteRecordRaw[],
})

function fatteningRoutes(routes: VabRouteRecord[]): VabRouteRecord[] {
  return routes.flatMap((route: VabRouteRecord) => {
    return route.children ? fatteningRoutes(route.children) : route
  })
}

function addRouter(routes: VabRouteRecord[]) {
  routes.forEach((route: VabRouteRecord) => {
    if (!router.hasRoute(route.name)) router.addRoute(route as RouteRecordRaw)
    if (route.children) addRouter(route.children)
  })
}

export function resetRouter(routes: VabRouteRecord[] = constantRoutes) {
  routes.map((route: VabRouteRecord) => {
    if (route.children) route.children = fatteningRoutes(route.children)
  })
  router.getRoutes().forEach(({ name }) => {
    router.hasRoute(<RouteRecordName>name) &&
      router.removeRoute(<RouteRecordName>name)
  })
  addRouter(routes)
}

export function setupRouter(app: any) {
  if (authentication === 'intelligence') addRouter(asyncRoutes)
  setupPermissions(router)
  app.use(router)
  return router
}

export default router
